<?php
header("Access-Control-Allow-Origin: *");
?>

<?php
$username = "pocketgames_dk";
$password = "mHiRL4bV";
$hostname = "pocketgames.dk.mysql"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");

//select a database to work with
$selected = mysql_select_db("pocketgames_dk",$dbhandle) or die("Could not select database");

//execute the SQL query and return records
$result = mysql_query("SELECT id, question, answer FROM Quiz");

$rows = array();
while($r = mysql_fetch_assoc($result)) {
    $rows[] = $r;
}

$results = array_map(function($r) {
                         $r['question'] = base64_encode(utf8_encode($r['question']));
                         $r['answer'] = base64_encode(utf8_encode($r['answer']));
                         return $r;
                         }, $rows);
    
$str = json_encode($results);
echo $str;
mysql_close($dbhandle);

?>